import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context('notebook', font_scale=1.5, rc={'lines.markeredgewidth': 2})
%load_ext autoreload
%autoreload 2
%matplotlib inline
from visual_behavior.data_access import loading as loading
from allensdk.brain_observatory.behavior.behavior_project_cache import VisualBehaviorOphysProjectCache
import visual_behavior.visualization.utils as utils
import visual_behavior.data_access.utilities as utilities
import visual_behavior.visualization.ophys.platform_paper_figures as ppf
cache_dir = loading.get_platform_analysis_cache_dir()
cache = VisualBehaviorOphysProjectCache.from_s3_cache(cache_dir=cache_dir)
# print(cache_dir)
experiments_table = loading.get_platform_paper_experiment_table()
print(len(experiments_table))
experiments_table = utilities.add_cell_type_column(experiments_table)
experiments_table = utilities.add_experience_exposure_column(experiments_table)
experiments_table = utilities.add_binned_depth_column(experiments_table)
experience_level = np.sort(experiments_table.experience_level.unique())
print(experience_level)
exposures = np.sort(experiments_table.experience_exposure.unique())
print(exposures)
cell_types = np.sort(experiments_table.cell_type.unique() )
print(cell_types)
%%time
# set various params
df_name = 'trials_response_df'
conditions = ['cell_specimen_id', 'stimulus_change', 'epoch']
use_events = True
filter_events = False
# load multi_session_df
multi_session_df = loading.get_multi_session_df(cache_dir, df_name, conditions, experiments_table,
use_events=use_events, filter_events=filter_events)
print(len(multi_session_df.ophys_experiment_id.unique()))
original_multi_session_df = multi_session_df.copy()
# keep changes only
multi_session_df = multi_session_df[multi_session_df.stimulus_change==True]
# limit to platform paper dataset
multi_session_df = multi_session_df[multi_session_df.ophys_experiment_id.isin(experiments_table.index.values)]
print(len(multi_session_df.ophys_experiment_id.unique()))
# merge with metadata
multi_session_df = multi_session_df.merge(experiments_table, on='ophys_experiment_id')
print(len(multi_session_df.ophys_experiment_id.unique()))
multi_session_df = multi_session_df.reset_index()
multi_session_df = multi_session_df[multi_session_df.epoch!=6] # its the 6th index
def merge_experience_epoch(row):
return row.experience_level+' epoch '+str(int(row.epoch)+1)
multi_session_df['experience_epoch'] = multi_session_df[['experience_level', 'epoch']].apply(axis=1, func=merge_experience_epoch)
experience_epoch = np.sort(multi_session_df.experience_epoch.unique())
experience_epoch
df = multi_session_df.copy()
df = df.reset_index()
utilities.count_mice_expts_containers_cells(df)
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=df[df.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=df[df.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
df = multi_session_df.copy()
df = utilities.limit_to_containers_with_all_experience_levels(df)
utilities.count_mice_expts_containers_cells(df)
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=df[df.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=df[df.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
df = multi_session_df.copy()
df = utilities.limit_to_last_familiar_second_novel_active(df)
df = utilities.limit_to_containers_with_all_experience_levels(df)
utilities.count_mice_expts_containers_cells(df)
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=df[df.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=df[df.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
df = multi_session_df.copy()
df = utilities.limit_to_cell_specimen_ids_matched_in_all_experience_levels(df)
utilities.count_mice_expts_containers_cells(df)
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=df[df.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=df[df.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
df = multi_session_df.copy()
df = utilities.limit_to_last_familiar_second_novel_active(df)
df = utilities.limit_to_cell_specimen_ids_matched_in_all_experience_levels(df)
utilities.count_mice_expts_containers_cells(df)
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=df[df.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=df[df.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.04, color='gray', linestyle='--')
data = df.copy()
data = data[data.targeted_structure=='VISl']
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=data[data.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=data[data.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.05, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.05, color='gray', linestyle='--')
data = df.copy()
data = data[data.project_code=='VisualBehaviorMultiscope']
fig, ax = plt.subplots(figsize=(8,5))
ax2 = ax.twinx()
cre_line_colors = utils.get_cre_line_colors()
ax2 = sns.pointplot(data=data[data.cell_type==cell_types[0]], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors, hue_order=cell_types, ax=ax2)
ax2.set_ylabel('excitatory mean response')
ax2.legend(bbox_to_anchor=(1.6,1))
ax2.set_ylim(ymin=0)
ax = sns.pointplot(data=data[data.cell_type.isin(cell_types[1:])], x='experience_epoch', y='mean_response', hue='cell_type',
order=experience_epoch, palette=cre_line_colors[1:], hue_order=cell_types[1:], ax=ax)
ax.set_ylabel('inhibitory mean response')
ax.set_ylim(ymin=0)
# ax.legend(bbox_to_anchor=(1.2,1))
ax.get_legend().remove()
ax.set_xticklabels(experience_epoch, rotation=90);
ax.set_title('average change evoked response over time')
ax.vlines(x=5.5, ymin=0, ymax=0.02, color='gray', linestyle='--')
ax.vlines(x=11.5, ymin=0, ymax=0.02, color='gray', linestyle='--')
df = multi_session_df.copy()
df = df.sort_values(by=['experience_level', 'mouse_id'])
multi_session_df[multi_session_df.ophys_container_id==1018028218].experience_level.unique()
df[df.ophys_container_id==1018028218].experience_level.unique()
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data.groupby(['experience_level', 'epoch', 'cell_type', 'mouse_id', ]).mean()[['mean_response']].unstack(level=[0,1])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(15,15))
ax = sns.heatmap(data, vmin=0, vmax=0.005, ax=ax)
df = df.sort_values(by=['experience_level', 'mouse_id', 'targeted_structure', 'depth', ])
np.sort(df.experience_level.unique())
df[df.ophys_container_id==1018028218]
data
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data.groupby(['experience_level', 'epoch', 'cell_type', 'mouse_id', ]).mean()[['mean_response']].unstack(level=[0,1])
data.columns = data.columns.droplevel()
conditions = ['experience_level', 'epoch', 'targeted_structure', 'depth', 'mouse_id', ]
for cell_type in cell_types:
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0,1])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(16,8))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(df[df.cell_type==cell_type].mean_response.values, 95), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
experiments_table[(experiments_table.mouse_id==482853)&(experiments_table.targeted_structure=='VISl')&
(experiments_table.depth==350)]
for cell_type in cell_types:
# avg over mice
conditions = ['experience_level', 'epoch', 'targeted_structure', 'depth']
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0,1])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(16,4))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(df[df.cell_type==cell_type].mean_response.values, 95), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
# all mice
conditions = ['experience_level', 'epoch', 'targeted_structure', 'depth', 'mouse_id']
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0,1])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(16,12))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(df[df.cell_type==cell_type].mean_response.values, 95), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
conditions = ['experience_level', 'epoch', 'targeted_structure', 'depth']
for cell_type in cell_types:
# avg over mice
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0,1])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(16,4))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(df[df.cell_type==cell_type].mean_response.values, 95), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
conditions = ['experience_level', 'epoch', 'project_code', 'mouse_id', 'targeted_structure', 'depth']
for cell_type in cell_types:
# all mice
data = df[df.epoch!=6].copy() # get rid of weird last epoch
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0, 1])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(16,12))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(df[df.cell_type==cell_type].mean_response.values, 95), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
df = multi_session_df.copy()
conditions = ['experience_level', 'targeted_structure', 'depth']
for cell_type in cell_types:
# avg over mice
data = df.copy()
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0])
data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(5,4))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(df[df.cell_type==cell_type].mean_response.values, 80), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
%%time
# set various params
df_name = 'trials_response_df'
conditions = ['cell_specimen_id', 'stimulus_change', 'change_image_name']
use_events = True
filter_events = False
# load multi_session_df
multi_session_df = loading.get_multi_session_df(cache_dir, df_name, conditions, experiments_table,
use_events=use_events, filter_events=filter_events)
print(len(multi_session_df.ophys_experiment_id.unique()))
original_multi_session_df = multi_session_df.copy()
# limit to changes, pref stim
multi_session_df = multi_session_df[(multi_session_df.stimulus_change==True)&
(multi_session_df.pref_stim==True)]
# limit to platform paper dataset
multi_session_df = multi_session_df[multi_session_df.ophys_experiment_id.isin(experiments_table.index.values)]
print(len(multi_session_df.ophys_experiment_id.unique()))
# merge with metadata
multi_session_df = multi_session_df.merge(experiments_table, on='ophys_experiment_id')
print(len(multi_session_df.ophys_experiment_id.unique()))
for cell_type in cell_types:
df = multi_session_df.copy()
df = df[df.cell_type==cell_type]
for project_code in df.project_code.unique():
fig, ax = plt.subplots(figsize=(15,5))
ax = sns.pointplot(data=df[df.project_code==project_code], x='experience_level', y='mean_response', hue='mouse_id',
order=np.sort(df.experience_level.unique()), ax=ax)
ax.get_legend().remove()
ax.set_title(cell_type+', '+project_code)
multi_session_df.keys()
data
conditions = ['experience_exposure', 'project_code', 'mouse_id', 'targeted_structure', 'depth']
for cell_type in cell_types:
# all mice
data = multi_session_df.copy()
data = data[data.cell_type==cell_type]
data = data.sort_values(by=conditions)
data = data.groupby(conditions).mean()[['mean_response']].unstack(level=[0])
# data.columns = data.columns.droplevel()
fig, ax = plt.subplots(figsize=(16,12))
ax = sns.heatmap(data, vmin=0, vmax=np.percentile(multi_session_df[multi_session_df.cell_type==cell_type].mean_response.values, 95), ax=ax)
ax.set_title(cell_type)
ax.set_ylim(-0.5, data.shape[0]+0.5)
### i
TBD: interpolate to average scientifica & multiscope
os.path.join(loading.get_platform_analysis_cache_dir(), 'multi_session_summary_dfs_250ms')
%%time
# set various params
df_name = 'trials_response_df'
conditions = ['cell_specimen_id', 'stimulus_change']
use_events = True
filter_events = True
# load multi_session_df
multi_session_df = loading.get_multi_session_df(cache_dir, df_name, conditions, experiments_table,
use_events=use_events, filter_events=filter_events)
print(len(multi_session_df.ophys_experiment_id.unique()))
original_multi_session_df = multi_session_df.copy()
# limit to changes, pref stim
multi_session_df = multi_session_df[(multi_session_df.stimulus_change==True)]
# limit to platform paper dataset
multi_session_df = multi_session_df[multi_session_df.ophys_experiment_id.isin(experiments_table.index.values)]
print(len(multi_session_df.ophys_experiment_id.unique()))
# merge with metadata
multi_session_df = multi_session_df.merge(experiments_table, on='ophys_experiment_id')
print(len(multi_session_df.ophys_experiment_id.unique()))
# set project code
project_code = 'VisualBehaviorMultiscope'
# get timestamps
multiscope_expt = experiments_table[experiments_table.project_code==project_code].index.values[9]
timestamps = ppf.get_timestamps_for_response_df_type(cache, multiscope_expt, df_name)
# plot
axes_column = 'cell_type'
hue_column = 'experience_level'
palette = utilities.get_experience_level_colors()
xlim_seconds = [-1.8,2.25]
df = multi_session_df[multi_session_df.project_code==project_code]
df = df[df.experience_level!='Novel >1']
ppf.plot_population_averages_for_conditions(df, df_name, timestamps,
axes_column, hue_column, project_code=project_code,
use_events=use_events, filter_events=filter_events,
xlim_seconds=xlim_seconds, palette=palette,
horizontal=True, save_dir=None, folder=None)
%%time
# set various params
df_name = 'trials_response_df'
conditions = ['cell_specimen_id', 'stimulus_change', 'change_image_name']
use_events = True
filter_events = True
# load multi_session_df
multi_session_df = loading.get_multi_session_df(cache_dir, df_name, conditions, experiments_table,
use_events=use_events, filter_events=filter_events)
print(len(multi_session_df.ophys_experiment_id.unique()))
original_multi_session_df = multi_session_df.copy()
# limit to changes, pref stim
multi_session_df = multi_session_df[(multi_session_df.stimulus_change==True)]
# limit to platform paper dataset
multi_session_df = multi_session_df[multi_session_df.ophys_experiment_id.isin(experiments_table.index.values)]
print(len(multi_session_df.ophys_experiment_id.unique()))
# merge with metadata
multi_session_df = multi_session_df.merge(experiments_table, on='ophys_experiment_id')
print(len(multi_session_df.ophys_experiment_id.unique()))
# plot
project_code = 'VisualBehaviorMultiscope'
# get timestamps
multiscope_expt = experiments_table[experiments_table.project_code==project_code].index.values[9]
timestamps = ppf.get_timestamps_for_response_df_type(cache, multiscope_expt, df_name)
axes_column = 'cell_type'
hue_column = 'experience_level'
palette = utilities.get_experience_level_colors()
xlim_seconds = [-1.8,2.25]
df = multi_session_df[multi_session_df.project_code==project_code]
df = df[df.experience_level!='Novel >1']
df = df[df.pref_stim==True]
ppf.plot_population_averages_for_conditions(df, df_name, timestamps,
axes_column, hue_column, project_code=project_code,
use_events=use_events, filter_events=filter_events,
xlim_seconds=xlim_seconds, palette=palette,
horizontal=True, save_dir=None, folder=None)
%%time
# set various params
df_name = 'omission_response_df'
conditions = ['cell_specimen_id']
use_events = True
filter_events = True
# load multi_session_df
multi_session_df = loading.get_multi_session_df(cache_dir, df_name, conditions, experiments_table,
use_events=use_events, filter_events=filter_events)
print(len(multi_session_df.ophys_experiment_id.unique()))
original_multi_session_df = multi_session_df.copy()
# limit to changes, pref stim
# multi_session_df = multi_session_df[(multi_session_df.stimulus_change==True)]
# limit to platform paper dataset
multi_session_df = multi_session_df[multi_session_df.ophys_experiment_id.isin(experiments_table.index.values)]
print(len(multi_session_df.ophys_experiment_id.unique()))
# merge with metadata
multi_session_df = multi_session_df.merge(experiments_table, on='ophys_experiment_id')
print(len(multi_session_df.ophys_experiment_id.unique()))
# plot
project_code = 'VisualBehaviorMultiscope'
# get timestamps
multiscope_expt = experiments_table[experiments_table.project_code==project_code].index.values[9]
timestamps = ppf.get_timestamps_for_response_df_type(cache, multiscope_expt, df_name)
axes_column = 'cell_type'
hue_column = 'experience_level'
palette = utilities.get_experience_level_colors()
xlim_seconds = [-1.8,2.25]
df = multi_session_df[multi_session_df.project_code==project_code]
df = df[df.experience_level!='Novel >1']
ppf.plot_population_averages_for_conditions(df, df_name, timestamps,
axes_column, hue_column, project_code=project_code,
use_events=use_events, filter_events=filter_events,
xlim_seconds=xlim_seconds, palette=palette,
horizontal=True, save_dir=None, folder=None)
%%time
# set various params
df_name = 'trials_response_df'
conditions = ['cell_specimen_id', 'stimulus_change']
use_events = False
filter_events = False
# load multi_session_df
multi_session_df = loading.get_multi_session_df(cache_dir, df_name, conditions, experiments_table,
use_events=use_events, filter_events=filter_events)
print(len(multi_session_df.ophys_experiment_id.unique()))
original_multi_session_df = multi_session_df.copy()
# limit to changes, pref stim
multi_session_df = multi_session_df[(multi_session_df.stimulus_change==True)]
# limit to platform paper dataset
multi_session_df = multi_session_df[multi_session_df.ophys_experiment_id.isin(experiments_table.index.values)]
print(len(multi_session_df.ophys_experiment_id.unique()))
# merge with metadata
multi_session_df = multi_session_df.merge(experiments_table, on='ophys_experiment_id')
print(len(multi_session_df.ophys_experiment_id.unique()))
# plot
project_code = 'VisualBehaviorMultiscope'
# get timestamps
multiscope_expt = experiments_table[experiments_table.project_code==project_code].index.values[9]
timestamps = ppf.get_timestamps_for_response_df_type(cache, multiscope_expt, df_name)
axes_column = 'cell_type'
hue_column = 'experience_level'
palette = utilities.get_experience_level_colors()
xlim_seconds = [-1.8,2.25]
df = multi_session_df[multi_session_df.project_code==project_code]
ppf.plot_population_averages_for_conditions(df, df_name, timestamps,
axes_column, hue_column, project_code=project_code,
use_events=use_events, filter_events=filter_events,
xlim_seconds=xlim_seconds, palette=palette,
horizontal=True, save_dir=None, folder=None)
hue_column = 'prior_exposures_to_omissions'
axes_column= 'cell_type'
palette = sns.color_palette('magma',8)
xlim_seconds = [-1.8,2.25]
df = multi_session_df.copy()
df = df[df.experience_level=='Familiar']
df = df[df.prior_exposures_to_omissions<=6]
ppf.plot_population_averages_for_conditions(df, df_name, timestamps,
axes_column, hue_column, project_code=project_code,
use_events=use_events, filter_events=filter_events,
xlim_seconds=xlim_seconds, palette=palette,
horizontal=True, save_dir=None, folder=None)
axes_column = 'experience_level'
hue_column = 'cell_type'
palette = utils.get_cre_line_colors()
xlim_seconds = [-1.8,2.25]
ppf.plot_population_averages_for_conditions(df, df_name, timestamps,
axes_column, hue_column, project_code=project_code,
use_events=use_events, filter_events=filter_events,
xlim_seconds=xlim_seconds, palette=palette,
horizontal=True, save_dir=None, folder=None)
matched_cells = pd.read_csv(r"\\allen\programs\braintv\workgroups\nc-ophys\visual_behavior\platform_paper_cache\matched_cell_lists\cells_matched_across_experience_levels_full_dataset.csv")
matched_cell_ids = matched_cells.cell_specimen_id.unique()
sdf = multi_session_df.copy()
# sdf = sdf[sdf.cell_specimen_id.isin(matched_cell_ids)]
sdf = sdf.sort_values(by='date_of_acquisition', ascending=True)
sdf = sdf.drop_duplicates(subset=['cell_specimen_id', 'experience_level'], keep='first')
row_condition = 'cell_type'
col_condition = 'experience_level'
xlim_seconds = [(3-1.8)*11,(3+2.25)*11]
ppf.plot_response_heatmaps_for_conditions(sdf, df_name, timestamps,
row_condition, col_condition, use_events, filter_events, project_code=project_code,
microscope='Multiscope', vmax=0.04, xlim_seconds=xlim_seconds,
match_cells=True, save_dir=None, folder=None)